<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>课程信息</title>
    <script src="js/jquery-3.4.1.min.js"></script>
    <script>
        history.pushState(null, null,document. URL);
        window.addEventListener( 'popstate', function () {
            history.pushState( null, null, document. URL);}
        );

        $(function(){
            //防止后退
            // if (window.history && window.history.pushState) {
            //     $(window).on('popstate', function () {
            //         window.history.pushState('forward', null, '#');
            //         window.history.forward(1);
            //     });
            // }
            // window.history.pushState('forward', null, '#'); //在IE中必须得有这两行
            // window.history.forward(1);

            //
           $("#go").click(function () {
               window.location="subjectServlet?pageNo="+$(this).prev().val();
           });
           //
            //
        });
    </script>
</head>
<body>
<%@include file="/WEB-INF/jsp/checkLogin.jsp"%>
<%--<%
    //session.invalidate();
    Admin admin=(Admin)session.getAttribute("USER");
    if(admin==null){
        response.sendRedirect("login.jsp?errmsg=You not login in");
        return;
    }
%>--%>

<h1>课程信息表</h1>
<p>
    <a href="toAddSubject">增加新课程</a>
</p>
<p style="color:red;">
    ${msg}
    <c:remove var="msg"/>

</p>
<table border="1" cellspacing="0" cellpadding="0">
    <tr>
        <td>课程号</td><td>课程名</td><td>学时</td><td>年级号</td><td>操作</td>
    </tr>

    <c:forEach items="${p.data}" var="s">
    <tr>
        <td>${s.id}</td><td>${s.subjectname}</td><td>${s.getClasshour()}</td><td>${s.gname}</td>
        <td><a href="delSubject?id=${s.id}">删除</a> <a href="toUpdateSubject?id=${s.id}">修改</a> </td>
    </tr>
    </c:forEach>
</table>
<p>

    <a href="subjectServlet?pageNo=1">首页</a>

    <c:if test="${p.pageNo>1}">
    <a href="subjectServlet?pageNo=${p.pageNo-1}">上一页</a>
    </c:if>
    <input type="number" min="1" value="${p.pageNo}" max="${p.totalPages}" name="pageNo" width="40px" size="4"/><input type="button" id="go" value="go" style="width: 60px;"/>

    <c:if test="${p.pageNo<p.totalPages}">
    <a href="subjectServlet?pageNo=${p.pageNo+1}">下一页</a>
    </c:if>
    <a href="subjectServlet?pageNo=${p.totalPages}">最后一页</a>
</p>
</body>
</html>